<?php

function CreateQueryInsert($array, $table)
{
	$ChampDB = '';
	$ValeurChamp = '';
	
	foreach($array as $key => $value)
	{
		if($ChampDB == '')
			$ChampDB .= $key;
		else
			$ChampDB .= ','.$key;
		
		if($ValeurChamp == '')
			$ValeurChamp .= "'".$value."'";
		else
			$ValeurChamp .= ",'".$value ."'";
	}
	
	$query = "INSERT INTO ". $table ." (". $ChampDB .") VALUES (". $ValeurChamp .")";
	
	return $query;
}

function CreateQueryUpdate($array, $table, $conditions = '', $secure = false)
{
	$ChampDB = '';
	$ValeurChamp = '';
	
	foreach($array as $key => $value)
	{
		if($ChampDB == '')
        {
            $ChampDB .=  $key ." =  '". secure_query($value, $secure)  ."'";   
        }
		else
        {
            $ChampDB .= ",".  $key ." =  '". secure_query($value, $secure) ."'";  
        }
			
	}
	
	$query = "UPDATE ". $table ." SET ". $ChampDB ." WHERE ". $conditions ;
	
	return $query;
}

function secure_query($str, $secure)
{
    if($secure)
    {
        return addslashes($str);
    }    
    else
    {
        return $str;
    }
}
?>
